package com.example.myspringboot.design.many;

import java.util.concurrent.*;

/**
 * @Author ZhengShan
 * @Date 2024 06 24 15 59
 **/
public class ManyTest {

    public static void main(String[] args) {
        int corePoolSize = 5;
        int maximumPoolSize = 10;
        long keepAliveTime = 60L;
        TimeUnit unit = TimeUnit.SECONDS;
        // 设置队列为有界队列，容量为100
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(100);
        // 使用默认线程工厂
        ThreadFactory threadFactory = Executors.defaultThreadFactory();
        // 设置拒绝策略为抛出异常
        RejectedExecutionHandler handler = new ThreadPoolExecutor.AbortPolicy();

        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue, threadFactory, handler );

        for(int i=0; i<100; i++) {
            executor.execute(() -> {
                    ManyDemo.getInstance();
                }
            );
        }
        executor.shutdown();
    }
}
